# -*- coding:utf-8 -*-
import json
import os,shutil

ROOT_PATH=os.path.abspath(os.path.dirname(os.getcwd()))
ROOT_PYTHON_PATH=os.path.abspath(os.path.dirname(os.getcwd()))+"/stock_py/data"
ROOT_JS_DATA_PATH=os.path.abspath(os.path.dirname(os.getcwd()))+"/stock_js/src/components/Utils/data"

class StockFileManager:
    def __init__(self,sql_obj):
        self.sql_obj=sql_obj
        pass
    
    
    #shutil.copyfile应用,参数必须具体到文件名
    @classmethod
    def recopyfile(self,srcfile,dstfile):
        if not os.path.isfile(srcfile):
            print(("%s not exit!" % (srcfile)))
        else:
            fpath,fname=os.path.split(dstfile)

            if not os.path.exists(fpath):
                os.makedirs(fpath)
                shutil.copyfile(srcfile,dstfile)
            else:
                shutil.copyfile(srcfile,dstfile)
    
    @classmethod
    def rewriteDataToFile(self,JSON_DATA,fileName):
        js_rps_path=ROOT_JS_DATA_PATH+"/"+fileName+".json"
        with open(js_rps_path,'w') as f:
            #json 存到本地
            f.write( json.dumps( JSON_DATA,ensure_ascii=False,indent=2 ) )

        
          